<?php
	require '../include/library.inc.php';
	require '../include/admin_login.inc.php';
	require '../include/paging.inc.php';
	
	
	$lang = 1;
	$sql = "SELECT
				user_id,
				email,
				full_name,
				accsess,
				news
			FROM
				users		
			";
	
	
	if (!isset($_GET['sort'])) $_GET['sort'] = 1;
	if (!isset($_GET['sortBy'])) $_GET['sortBy'] = 1;
	
	$paging = new Paging($sql, $_GET['sortBy'], $_GET['sort'], array(1=>"Подредба"), 30);
	$result = $paging->query();
		
		head_admin("Потребители");
	?>
			
				<?php if ($_SESSION['message']) { ?>
				<div class="message green">
					<?=$_SESSION['message']?>
				</div>
				<?php unset($_SESSION['message']); } ?>
			
			
				<div class="topbuttons">
					<a href="user_new.php">Добави нов потребител</a>
					
				</div>
				<h3>Потребители (<?=$paging->count()?>)</h3>
				
				<table id="listing" width="100%" cellpadding="0" cellspacing="0">
					<thead>
                        <tr>
                            <td>Име</td>
                            <td>e-mail</td>
                            <td>Admin</td>
                            <td>Действия</td>
                        </tr>
                    </thead>
				<tbody>
				<?php
				  
				  
				  $i=1;
				  while ($row = mysql_fetch_object($result)) {				  
				?>
						<tr class="<?=(($i%2)?"none":"zebra")?>">
							<td>
                            	<a href="user_edit.php?user_id=<?=$row->user_id?>" title="Редактирай"><?=sth($row->full_name)?></a></td>
							<td>
							e-mail:
                            	<a href="mailto:<?=$row->email?>"><?=$row->email?></a>
							</td>
							<td class="switch">
								<?php if ($row->accsess) { ?>
								 <a href="user_admin.php?user_id=<?=$row->user_id?>&publish=0" class="turn_on" name="turn_on" title="Спри админ права"></a>
								<?php } else { ?> 
								 <a href="user_admin.php?user_id=<?=$row->user_id?>&publish=1" class="turn_off" name="turn_off" title="Направи админ"></a>
								<?php } ?>	
							</td>
							
							
							<td class="icons">
								
								<a href="user_edit.php?user_id=<?=$row->user_id?>" class="edit" title="Редактирай">Редактирай</a> 
								<a onClick="if (window.confirm('Сигурен ли си, че искаш да изтриеш <?=sth($row->Name)?>?')) { document.location='user_del.php?user_id=<?=$row->user_id?>'; return false; }" class="delete" title="Изтрий">Изтрий</a>
							</td>
							
						</tr>
			 <?php
				  $i++;    
				} 
			 ?>				  
				</tbody>
			</table>
			
			<div class="pagingwrap"><div class="paging">
				<?=$paging->display()?>
			</div></div>
            
<?php
	foot_admin(); 
?>